package com.meixiang.activity.calendar;

import android.app.Activity;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lzy.okhttputils.model.HttpParams;
import com.meixiang.R;
import com.meixiang.global.Config;
import com.meixiang.http.HttpCallBack;
import com.meixiang.http.HttpUtils;
import com.meixiang.main.BaseActivity;
import com.meixiang.tool.Tool;
import com.meixiang.view.ClearEditText;
import com.meixiang.view.wheel.time.TimeSelectDialog;

import org.json.JSONObject;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 备忘录
 * author：wangzuzhen on 2016/5/5 0005 15:07.
 */
public class MemorandumActivity extends BaseActivity {

    @Bind(R.id.ce_memorandum_title)
    ClearEditText mCeMemorandumTitle;
    @Bind(R.id.tv_date)
    TextView mTvDate;
    @Bind(R.id.rl_memorandum_time)
    RelativeLayout mRlMemorandumTime;

    private Activity mActivity;
    private String year,month,day,data,calendarData,monthday,times;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.activity_memorandum);
        ButterKnife.bind(this);
        mActivity=MemorandumActivity.this;
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void initTitle() {
        if(!Tool.isBlank(getIntent().getStringExtra("year"))){
            year=getIntent().getStringExtra("year");

        }
        if(!Tool.isBlank(getIntent().getStringExtra("month"))){
            month=getIntent().getStringExtra("month");

        }
        if(!Tool.isBlank(getIntent().getStringExtra("day"))){
            day=getIntent().getStringExtra("day");

        }
        //提交
        Log.e("TAG","得到当前时间data==="+year+"年"+mTvDate.getText().toString());
//                        06-4;

        data=Tool.getTime(Tool.toDays(month)+"-"+Tool.toDays(day));
        setRightTitle(getResources().getString(R.string.add_memorandum), getResources().getString(R.string.memorandum_confirm),
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if(TextUtils.isEmpty(times)){
                            Tool.showTextToast(mActivity,"请选择时间");
                            return;
                        }
                        if(TextUtils.isEmpty(mCeMemorandumTitle.getText().toString())){
                            Tool.showTextToast(mActivity,"请填写描述内容");
                            return;
                        }
                        calendarData=Tool.getData(year+"年"+monthday)+" "+times;

                        goSubmit(calendarData,mCeMemorandumTitle.getText().toString());

                    }
                });
    }

    @Override
    protected void initView() {
//        mTvDate.setText(Tool.getPaymentMoneyPerMonth(BigDecimal.valueOf(1000.00),3,BigDecimal.valueOf(0.0003))+"");

    }

    @Override
    protected void setData() {

    }

    @OnClick({R.id.rl_memorandum_time})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.rl_memorandum_time:
                TimeSelectDialog timeSelectDialog = new TimeSelectDialog(context,data, "时间选择","取消", "完成", new TimeSelectDialog.TimeSelectListener() {
                    @Override
                    public void getTimeSelect(String date,String time) {
                        mTvDate.setText(date+"  "+time);
                        monthday=date;
                        times=time;
                        Log.e("TAG","得到数据 date=="+date+"---time"+time);
                    }
                });
                timeSelectDialog.show();
                break;
        }
    }

    //提交
    public void goSubmit(String data,String title){
        HttpParams params=new HttpParams();
        params.put("remindTime",data);
        params.put("title",title);
        HttpUtils.post(Config.CALENDAR_BACKUPEDIT, params, new HttpCallBack(mActivity) {
            @Override
            public void onSucceed(JSONObject result, String code, String message) {
                Log.e("TAG","得到返回值=="+result.toString());
                Tool.showTextToast(mActivity,message);
                finish();
            }
            @Override
            public void onError(String code, String message) {
                Tool.showTextToast(mActivity,message);
            }
        });

    }

}
